layui.use(['laydate', 'jquery'], function () {
    var laydate = layui.laydate;
    var $ = layui.$;

    // 加载日期组件
    laydate.render({
        elem: '#shijian'
    });

    // 给添加按钮绑定点击事件
    $(".layui-btn").click(function () {
        var time = $("#shijian").val();
        var pic = $("#tupian").val();
        var content = $("#neirong").val();
        var cc = "<li class=\"layui-timeline-item\">" +
            "<i class=\"layui-icon layui-timeline-axis\">&#xe63f;</i>" +
            "<div class=\"layui-timeline-content layui-text\">" +
            "<h3 class=\"layui-timeline-title\">" + time + "</h3>" +
            "<p>" + content + "</p>" +
            "<img src=\"" + pic + "\" >" +
            "</div>" +
            "</li>";

        // 给时间线添加子元素
        $(".layui-timeline").append(cc);
        // 将添加的子元素发到后台，存入数据库
        $.post("insertTimeLine", {time: time, content: content, pic: pic}, function (result) {
        });
    });

    // 获取时间线内容
    $.get("timeLine", function (data) {
            $.each(data, function (i, e) {
                $(".layui-timeline").append(e.content)
            });
        }
    );

    // 获取内容
    $("#time").dblclick(function () {
        $.get("timeContent?time=" + $("#shijian").val(), function (data) {
                $("#neirong").val(data)
            }
        );
    });
});